package com.jshan.controller;

import com.jshan.base.vo.Result;
import com.jshan.base.dto.CodeGenRequest;
import com.jshan.service.CodeGenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "代码生成器")
@RestController
@RequestMapping("/codegen")
public class CodeGenController {
    @Resource
    private CodeGenService codeGenService;

    @Operation(summary = "预览生成代码")
    @PostMapping("/preview")
    public Result<Map<String, String>> preview(@RequestBody CodeGenRequest request) {
        return Result.ok(codeGenService.preview(request));
    }

    @Operation(summary = "生成代码到指定目录")
    @PostMapping("/generate")
    public Result<Void> generate(@RequestBody CodeGenRequest request) {
        codeGenService.generate(request);
        return Result.ok();
    }
}
